﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace QuanLiGiaiBongDa
{
    public partial class frmQL_Doibong : Form
    {
        public frmQL_Doibong()
        {
            InitializeComponent();
        }


        DataTable dt = new DataTable();
        QuanLyDB_BLL ql = new QuanLyDB_BLL();
        private void frmQL_Doibong_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'quanLyBongDaDataSet.DOIBONG' table. You can move, or remove it, as needed.
            this.dOIBONGTableAdapter.Fill(this.quanLyBongDaDataSet.DOIBONG);
            // TODO: This line of code loads data into the 'quanLyBongDaDataSet.CAUTHU' table. You can move, or remove it, as needed.
            this.cAUTHUTableAdapter.Fill(this.quanLyBongDaDataSet.CAUTHU);
            LoadData_DB();
            //
            DataTable tblct = new DataTable();
            tblct = SQLProvider.GetDataTable("CAUTHU");
            dt = SQLProvider.GetDataTable("CAUTHU");
            Loadtreeview_DSCT(tblct, treeViewDscauthu);
            //
            DataTable tbldb = new DataTable();
            tbldb = SQLProvider.GetDataTable("DOIBONG");
            dt = SQLProvider.GetDataTable("DOIBONG");
            Loadtreeview_DB(tbldb, treeViewDsdoibong);
           
        }

        /// //////////////////////////
        /// tab danh sach doi bong
        public DoiBong GetValueForm()
        {
            DoiBong db = new DoiBong();
            db.Madb = this.txtMadoiBong.Text.ToUpper();
            db.Tendb = this.txttendoibong.Text;
            //dataGridViewdsdb2.DataSource = ql.TimMaSanTheoTen(cbmasan.Text);
            //db.Diachi = this.txtdiachidoibong.Text;
            //if (dataGridViewdsdb2[0, 0].Value != null)
            //    db.Masan = dataGridViewdsdb2[0, 0].Value.ToString();
            return db;
        }
        private void LoadData_DB()
        {
            dataGridViewdsdb.DataSource = ql.DSDoiBong(SQLProvider.GetAll("Doibong"));
            LoadComboboxMaSan();
        }
        void Loadtreeview_DB(DataTable tbldb, TreeView treL)
        {
                TreeNode nodeParent = treeViewDsdoibong.Nodes.Add("Danh Sách Đội Bóng");
                foreach (DataRow drwDb in tbldb.Rows)
                {
                    string Tendb = drwDb["TenDB"].ToString();
                    string dc = drwDb["DiaChi"].ToString();
                    string madoi = drwDb["MaDB"].ToString();
                    string masan = drwDb["MaSan"].ToString();
                    foreach (DataRow drw in tbldb.Rows)
                    {
                        if (drw["TenDB"].ToString().Equals(Tendb))
                        {
                            TreeNode nodeChild = new TreeNode();
                            nodeChild.Text = drw["TenDB"].ToString();
                            nodeParent.Nodes.Add(nodeChild);
                            if (drw["MaDB"].ToString().Equals(madoi))
                            {
                                TreeNode nChild = new TreeNode();
                                nChild.Text = "Mã Đội: " + drw["MaDB"].ToString();
                                nodeChild.Nodes.Add(nChild);
                            }
                            if (drw["MaSan"].ToString().Equals(masan))
                            {
                                TreeNode nChild = new TreeNode();
                                nChild.Text = "Mã Sân: " + drw["MaSan"].ToString();
                                nodeChild.Nodes.Add(nChild);
                            }
                            if (drw["DiaChi"].ToString().Equals(dc))
                            {
                                TreeNode nChild = new TreeNode();
                                nChild.Text = "Địa Chỉ: " + drw["DiaChi"].ToString();
                                nodeChild.Nodes.Add(nChild);
                            }
                        }
                        treeViewDsdoibong.ExpandAll();
                    }
                }
        }
        private void treeViewDsdoibong_AfterSelect(object sender, TreeViewEventArgs e)
        {
            int a = 0;
            if (treeViewDsdoibong.SelectedNode.Parent == null && treeViewDsdoibong.SelectedNode != null)
            {
                foreach (DataRow drwdb in dt.Rows)
                {
                    a++;
                }
                if (a != 0)
                    lblTongdoibong.Text = "Tổng số đội bóng là: " + a.ToString() + " đội bóng";
                else
                    lblTongdoibong.Text = "Chưa có đội bóng";
            }
        }
        public void LoadComboboxMaSan()
        {
            ql.MaSan(cbmasan);
        }
        private void dataGridViewdsdb_Click(object sender, EventArgs e)
        {
            if (dataGridViewdsdb.SelectedRows.Count > 0)
            {
                DataGridViewRow row = dataGridViewdsdb.SelectedRows[0];
                int vitricot = dataGridViewdsdb.Rows.IndexOf(row);
                txtMadoiBong.Text = dataGridViewdsdb[0, vitricot].Value.ToString();
                txtMadoiBong.Enabled = false;
                txttendoibong.Text = dataGridViewdsdb[1, vitricot].Value.ToString();
                cbmasan.Text = dataGridViewdsdb[2, vitricot].Value.ToString();
                txtdiachidoibong.Text = dataGridViewdsdb[3, vitricot].Value.ToString();
            }
        }
        private void cbmasan_KeyPress(object sender, KeyPressEventArgs e)
        {
            e.KeyChar = '\0';
        }    
        private void btdangky_Click(object sender, EventArgs e)
        {
            DBAccess db = new DBAccess();
            string _MADB = txtMadoiBong.Text;
            string _TenDB = txttendoibong.Text;
            string _MaSan = cbmasan.SelectedItem.ToString();
            string _DiaChi = txtdiachidoibong.Text;
            string sql = "insert into doibong values ('" + _MADB + "','" + _TenDB + "','" + _MaSan + "','" + _DiaChi + "',NULL,NULL,NULL)";
            db.ExecNonQuery(sql);
            MessageBox.Show("Insert Successful!", "Message", MessageBoxButtons.OK);
            string sql2 = "select * from doibong";
            dataGridViewdsdb.DataSource = db.ExecSQLDataTable(sql2);
            LoadData_DB();
        }
        private void btxoadoibong_Click(object sender, EventArgs e)
        {
            try
            {
                DBAccess db = new DBAccess();
                string _MaDB = txtMadoiBong.Text;
                string sql = "DELETE FROM doibong WHERE MaDB = '" + _MaDB + "'";
                db.ExecNonQuery(sql);
                MessageBox.Show("Xo´a Tha`nh Công ");
                string sql1 = "select * from DOIBONG";
                dataGridViewdsdb.DataSource = db.ExecSQLDataSet(sql1);
                LoadData_DB();
            }
            catch (Exception)
            { }
        }
       // SqlDataAdapter sda;
        private void btcapnhapdoibong_Click(object sender, EventArgs e)
        {
          /*  try
            {
                if (txtMadoiBong.Text.Equals(""))
                    return;
                DataTable dt = new DataTable();
                DBAccess db = new DBAccess();
                string sql = "select * from DoiBong";
                dt = db.ExecSQLDataTable(sql);
                DataRow row = dt.Rows.Find(txtMadoiBong.Text);
                row[2] = txttendoibong.Text;
                row[3] = cbmasan.SelectedItem;
                row[4] = txtdiachi.Text;
                sda.Update(dt);
            */
            try
            {
                DBAccess db = new DBAccess();
                string sql = "Update doibong Set TenDB='" + txttendoibong.Text + "',MaSan ='" + cbmasan.SelectedItem.ToString() + "'   where MaDB='" + txtMadoiBong.Text + "' ";
                db.ExecNonQuery(sql);
                MessageBox.Show("Insert Successful!", "Message", MessageBoxButtons.OK);
                string sql2 = "select * from doibong";
                dataGridViewdsdb.DataSource = db.ExecSQLDataTable(sql2);
                LoadData_DB();
            }
            catch (Exception)
            { }
        }
        private void btrefreshdoibong_Click(object sender, EventArgs e)
        {
            txtMadoiBong.Text = "";
            txttendoibong.Text = "";
            txtdiachidoibong.Text = "";
            cbmasan.Text = "";
            txtMadoiBong.Enabled = true;
            this.LoadData_DB();
        }

        /// /////////////////
        /// tab danh sach cau thu
        QuanLyCT_BLL ct = new QuanLyCT_BLL();
        void Loadtreeview_DSCT(DataTable tblct, TreeView treV)
        {
            TreeNode nParent = treeViewDscauthu.Nodes.Add("Danh Sách Cầu Thủ");
            foreach (DataRow drwct in tblct.Rows)
            {
                string Tenct = drwct["HoTen_CT"].ToString();
                string mCT = drwct["MaCT"].ToString();
                string madoi = drwct["MaDB"].ToString();
                string ngaysinh = drwct["NgaySinh"].ToString();
                string quoctich = drwct["QuocTich"].ToString();
                string vt = drwct["ViTri"].ToString();
                string soao = drwct["SoAo"].ToString();
                foreach (DataRow drw in tblct.Rows)
                {
                    if (drw["HoTen_CT"].ToString().Equals(Tenct))
                    {
                        TreeNode nodeChild = new TreeNode();
                        nodeChild.Text = drw["HoTen_CT"].ToString();
                        nParent.Nodes.Add(nodeChild);
                        if (drw["MaCT"].ToString().Equals(mCT))
                        {
                            TreeNode nChild = new TreeNode();
                            nChild.Text = "Mã CT: " + drw["MaCT"].ToString();
                            nodeChild.Nodes.Add(nChild);
                        }
                        if (drw["MaDB"].ToString().Equals(madoi))
                        {
                            TreeNode nChild = new TreeNode();
                            nChild.Text = "Mã Đội: " + drw["MaDB"].ToString();
                            nodeChild.Nodes.Add(nChild);
                        }
                        if (drw["NgaySinh"].ToString().Equals(ngaysinh))
                        {
                            TreeNode nChild = new TreeNode();
                            nChild.Text = "Ngày Sinh: " + drw["NgaySinh"].ToString();
                            nodeChild.Nodes.Add(nChild);
                        }
                        if (drw["QuocTich"].ToString().Equals(quoctich))
                        {
                            TreeNode nChild = new TreeNode();
                            nChild.Text = "Quốc Tịch: " + drw["QuocTich"].ToString();
                            nodeChild.Nodes.Add(nChild);
                        }
                        if (drw["ViTri"].ToString().Equals(vt))
                        {
                            TreeNode nChild = new TreeNode();
                            nChild.Text = "Vị Trí: " + drw["ViTri"].ToString();
                            nodeChild.Nodes.Add(nChild);
                        }
                        if (drw["SoAo"].ToString().Equals(soao))
                        {
                            TreeNode nChild = new TreeNode();
                            nChild.Text = "Số Áo: " + drw["SoAo"].ToString();
                            nodeChild.Nodes.Add(nChild);
                        }
                    }
                    treeViewDscauthu.ExpandAll();
                }
            }
        }
        private void treeViewDscauthu_AfterSelect(object sender, TreeViewEventArgs e)
        {}
        public CauThu GetValueForm_CT()
        {
            CauThu ct = new CauThu();
            ct.Mact = txtmacauthudsct.Text.ToUpper();
            ct.Hotenct = txthotendsct.Text;
            ct.Ngaysinh = dateTimePickerngaysinh.Value.Date;
            ct.Mavt = cbvitri.Text;
            ct.Quoctich = cbquoctich.Text;
            ct.Soao = numericUpDownsoao.Value.ToString();

            //dataGridViewdsct2.DataSource = ql.TimMaDBTheoTen(cbdoibong_dsct.Text);
            //if (dataGridViewdsct2[0, 0].Value != null)
            //    ct.Madb = dataGridViewdsct2[0, 0].Value.ToString();
            return ct;
        }
        private void LoadDanhSachCT()
        {
            dataGridViewdsct.DataSource =ct.DSCauThu(SQLProvider.GetAll("CauThu"));
        }
        private void LoadComboboxMaDB()
        {
            ql.MaDB(cbdoibong_dsct);
        }
        private void LoadComboboxQuocTich()
        {
            ql.QUOCTICH(cbquoctich);
        }
        private void txthotendsct_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!char.IsDigit(e.KeyChar))
                (sender as TextBox).ReadOnly = false;
            else
            {
                MessageBox.Show("Bạn chỉ được nhập chữ");
                (sender as TextBox).ReadOnly = true;
            }
        }
        private void cbdoibong_dsct_KeyPress(object sender, KeyPressEventArgs e)
        {
            e.KeyChar = '\0';
        }
        private void dataGridViewdsct_Click(object sender, EventArgs e)
        {
            if (dataGridViewdsct.SelectedRows.Count > 0)
            {
                DataGridViewRow row = dataGridViewdsct.SelectedRows[0];
                int vitricot = dataGridViewdsct.Rows.IndexOf(row);
                txtmacauthudsct.Text = dataGridViewdsct[0, vitricot].Value.ToString();
                txtmacauthudsct.Enabled = false;
                cbdoibong_dsct.Text = dataGridViewdsct[1, vitricot].Value.ToString();
                txthotendsct.Text = dataGridViewdsct[2, vitricot].Value.ToString();
                dateTimePickerngaysinh.Value = DateTime.Parse(dataGridViewdsct[4, vitricot].Value.ToString());;
                numericUpDownsoao.Value = int.Parse(dataGridViewdsct[5, vitricot].Value.ToString());
                cbvitri.Text = dataGridViewdsct[6, vitricot].Value.ToString();
                cbquoctich.Text = dataGridViewdsct[7, vitricot].Value.ToString();
            }
        }

        //  /////////////////////    
        // /// Tab San
        private void LoadSan()
        {
            dataGridView_San.DataSource = ql.San(SQLProvider.GetAll("San"));
        }
        private San GetValueSan()
        {
            San s = new San();
            s.Masan = txtmasan.Text.ToUpper();
            s.Tensan = txttensan.Text;
            s.Diachi = txtdiachi.Text;
            s.Succhua = int.Parse(txtsucchua.Text);
            return s;
        }
        private void txtsucchua_KeyPress(object sender, KeyPressEventArgs e)
        {
            if ((e.KeyChar < '0' || e.KeyChar > '9') && e.KeyChar != '\b')
            {
                MessageBox.Show("Bạn chỉ được nhập số.");
                e.KeyChar = '\0';
            }
        }
        private void dataGridView_San_Click(object sender, EventArgs e)
        {
            if (dataGridView_San.SelectedRows.Count > 0)
            {
                DataGridViewRow row = dataGridView_San.SelectedRows[0];
                int vitrirow = dataGridView_San.Rows.IndexOf(row);
                txtmasan.Text = dataGridView_San[0, vitrirow].Value.ToString();
                txtmasan.Enabled = false;
                txttensan.Text = dataGridView_San[1, vitrirow].Value.ToString();
                txtdiachi.Text = dataGridView_San[2, vitrirow].Value.ToString();
                txtsucchua.Text = dataGridView_San[3, vitrirow].Value.ToString();
            }
        }
        private void btthem_Click(object sender, EventArgs e)
        {
            string tensan = txttensan.Text;
            string masan = txtmasan.Text;
            if (!DataUtils.KiemTra(txtmasan.Text, txttensan.Text, txtdiachi.Text, txtsucchua.Text))
            {
                MessageBox.Show("Bạn chưa nhập đầy đủ thông tin");
            }
            else if (ql.Insert_San(GetValueSan()))
            {
                MessageBox.Show("Danh sach đã thêm sân " + tensan + ".");
                this.LoadSan();
            }
            else
            {
                SqlDataReader dr = SQLProvider.Execute_Reader(SQLProvider.GetAll("san"));
                int i = 0;
                while (dr.Read())
                {
                    string s1 = dr["tensan"].ToString();
                    string s2 = dr["masan"].ToString();

                    if (txttensan.Text.CompareTo(s1) == 0)
                    {
                        MessageBox.Show("Đã có sân " + tensan + " trong danh sach.");
                        break;
                    }
                    if (txtmasan.Text.ToUpper().CompareTo(s2) == 0)
                    {
                        MessageBox.Show(" Mã sân " + masan + " đã được sử dụng.\n Bạn hãy chọn mã sân khác.");
                        break;
                    }
                }
            }
        }
        private void btxoa_Click(object sender, EventArgs e)
        {
            string s = txttensan.Text;
            if (!DataUtils.KiemTra(txtmasan.Text))
            {
                MessageBox.Show("Bạn chưa nhập mã sân sẽ được xoá");
            }
            else if (ql.Delete_San(GetValueSan()))
            {
                MessageBox.Show("Sân " + s + " đã được xoá khỏi danh sách.");
                this.LoadSan();
            }
            else
            {
                MessageBox.Show("Xoá không thành công.\nHiện tại có đội bóng hay trận đấu đang sử dụng sân " + s + ".");
            }
        }
        private void btRefresh_Click(object sender, EventArgs e)
        {
            txtdiachi.Text = "";
            txttensan.Text = "";
            txtmasan.Text = "";
            txtsucchua.Text = "";
            txtmasan.Enabled = true;
            this.LoadSan();
        }
        private void btcapnhap_Click(object sender, EventArgs e)
        {
            if (!DataUtils.KiemTra(txtmasan.Text))
            {
                MessageBox.Show("Bạn chưa chọn sân để cập nhật");

            }
            else if (ql.Update_San(GetValueSan()))
            {
                MessageBox.Show("Thông tin đã được cập nhật");
                this.LoadSan();
            }
            else
            {
                MessageBox.Show("Cập nhật không thành công");
            }
        }


        //  /////////////////////    
        // /// Ban Huan Luyen

        private void LoadBHL()
        {
            dataGridViewbhl.DataSource = ql.BHL(SQLProvider.GetAll("BHL"));
        }
        private BHL GetValue_BHL()
        {
            BHL hl = new BHL();
            hl.Mabhl = txtMabhl.Text.ToUpper();
            hl.Hoten = txtHoten.Text;
            hl.Chucvu = cbchucvu.Text;

            dataGridViewbhl2.DataSource = ql.TimMaDBTheoTen(cbdoibong.Text);         
            if (dataGridViewbhl2[0, 0].Value != null)
                hl.Madb = dataGridViewbhl2[0, 0].Value.ToString();
            return hl;
        }
        private void dataGridViewbhl_Click(object sender, EventArgs e)
        {
            if (dataGridViewbhl.SelectedRows.Count > 0)
            {
                DataGridViewRow row = dataGridViewbhl.SelectedRows[0];
                int vitricot = dataGridViewbhl.Rows.IndexOf(row);
                txtMabhl.Text = dataGridViewbhl[0, vitricot].Value.ToString();
                txtHoten.Text = dataGridViewbhl[1, vitricot].Value.ToString();
                cbdoibong.Text = dataGridViewbhl[2, vitricot].Value.ToString();
                cbchucvu.Text = dataGridViewbhl[3, vitricot].Value.ToString();
                txtMabhl.Enabled = false;
            }
        }
        private void LoadComboboxMadb_BHL()
        {
            ql.MaDB(cbdoibong);
        }
        private void LoadComboboxChucVu_BHL()
        {
            ql.ChucVu(cbchucvu);
        }
        private void cbdoibong_KeyPress(object sender, KeyPressEventArgs e)
        {
            e.KeyChar = '\0';
        }
        private void txtHoten_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (char.IsNumber(e.KeyChar))
            {
                MessageBox.Show("Bạn chỉ được nhập chữ.");
                e.KeyChar = '\0';
            }
        }



        /// ///////////////////////
        /// ////////////////
        private void tabControl1_Selected(object sender, TabControlEventArgs e)
        {
            if (e.TabPageIndex == 1)
            {
                this.LoadDanhSachCT();
                LoadComboboxMaDB();
                LoadComboboxQuocTich();
            }

            if (e.TabPageIndex == 2)
                this.LoadSan();
            if (e.TabPageIndex == 3)
            {
                this.LoadBHL();
                cbdoibong.Items.Clear();
                LoadComboboxMadb_BHL();
                LoadComboboxChucVu_BHL();
                
            }
        }
        private void frmQL_Doibong_FormClosing(object sender, FormClosingEventArgs e)
        {
            DialogResult d = MessageBox.Show("Bạn muốn đóng Quản lý đội bóng?", "Thông Báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);
            if (d == DialogResult.No)
                e.Cancel = true;
        }

        private void btthembhl_Click(object sender, EventArgs e)
        {
            DBAccess db = new DBAccess();
            string _MABHL = txtMabhl.Text;
            string _HOTEN = txtHoten.Text;
            string _chucvu = cbchucvu.SelectedItem.ToString();
            string _doibong = cbdoibong.SelectedItem.ToString();
            string sql = "insert into bhl values ('" + _MABHL + "','" + _HOTEN + "','" + _doibong + "','" + _chucvu + "')";
            db.ExecNonQuery(sql);
            MessageBox.Show("Insert Successful!", "Message", MessageBoxButtons.OK);
            string sql2 = "select * from BHL";
            dataGridViewbhl.DataSource = db.ExecSQLDataTable(sql2);
            LoadBHL();
        }

        private void btthemcauthu_Click(object sender, EventArgs e)
        {
            DBAccess db = new DBAccess();
            string _MACT = txtmacauthudsct.Text;
            string _MADB = cbdoibong_dsct.SelectedItem.ToString();
            string _HOTEN = txthotendsct.Text;
            //ngay sinh null
            DateTime _NGAYSINH = Convert.ToDateTime(dateTimePickerngaysinh.Text);
            int _SOAO = Int32.Parse(numericUpDownsoao.Value.ToString());
            string _VITRI = cbvitri.SelectedItem.ToString();
            string _QUOCTICH = cbquoctich.SelectedItem.ToString();
            string sql = "insert into CAUTHU values ('" + _MACT + "','" + _MADB + "','" + _HOTEN + "',NULL,'" + _NGAYSINH + "'," + _SOAO + ",'" + _VITRI + "','" + _QUOCTICH + "',0,0)";
            db.ExecNonQuery(sql);
            MessageBox.Show("Insert Successful!", "Message", MessageBoxButtons.OK);
            string sql2 = "select * from cauthu";
            dataGridViewdsct.DataSource = db.ExecSQLDataTable(sql2);
            LoadDanhSachCT();
        }

        private void btxoacauthu_Click(object sender, EventArgs e)
        {

            try
            {
                DBAccess db = new DBAccess();
                string _MaCT = txtmacauthudsct.Text;
                string sql = "DELETE FROM cauthu WHERE MaCT = '" + _MaCT + "'";
                db.ExecNonQuery(sql);
                MessageBox.Show("Xóa Thành Công ");
                string sql1 = "select * from CauThu";
                dataGridViewdsdb.DataSource = db.ExecSQLDataSet(sql1);
                LoadDanhSachCT();
            }
            catch (Exception)
            { }
        }

        private void btRefreshcauthu_Click(object sender, EventArgs e)
        {

            txtmacauthudsct.Enabled = true;
            txtmacauthudsct.Text = "";
            txthotendsct.Text = "";
            cbquoctich.Text= "";
            cbdoibong_dsct.Text = "";
            dateTimePickerngaysinh.Text = "";
            cbvitri.Text = "";
            numericUpDownsoao.Value = 0;

            this.LoadDanhSachCT();
        }

        private void btcapnhapcauthu_Click(object sender, EventArgs e)
        {
            try
            {
                DBAccess db = new DBAccess();
                string sql = "Update cauthu Set MaDB='" + cbdoibong_dsct.SelectedItem.ToString() + "',QuocTich='" + cbquoctich.SelectedItem.ToString() + "',HoTen_CT ='" + txthotendsct.Text + "', NgaySinh='" + Convert.ToDateTime(dateTimePickerngaysinh.Text) + "',ViTri ='" + cbvitri.SelectedItem.ToString() + "'   where MaCT='" + txtmacauthudsct.Text + "' ";
                db.ExecNonQuery(sql);
                MessageBox.Show("Insert Successful!", "Message", MessageBoxButtons.OK);
                string sql2 = "select * from cauthu";
                dataGridViewdsdb.DataSource = db.ExecSQLDataTable(sql2);
                LoadDanhSachCT();
            }
            catch (Exception)
            { }
        }

        private void btxoabhl_Click(object sender, EventArgs e)
        {
            try
            {
                DBAccess db = new DBAccess();
                string _MaBHL = txtMabhl.Text;
                string sql = "DELETE FROM BHL WHERE MaBHL = '" + _MaBHL + "'";
                db.ExecNonQuery(sql);
                MessageBox.Show("Xóa Thành Công ");
                string sql1 = "select * from BHL";
                dataGridViewdsdb.DataSource = db.ExecSQLDataSet(sql1);
                LoadBHL();
            }
            catch (Exception)
            { }
        }

        private void btrefreshbhl_Click(object sender, EventArgs e)
        {
            txtMabhl.Enabled = true;
            txtMabhl.Text = "";
            txtHoten.Text = "";
            cbdoibong.Text = "";
            cbchucvu.Text = "";
        }

        private void btcapnhapbhl_Click(object sender, EventArgs e)
        {
            try
            {
                DBAccess db = new DBAccess();
                string sql = "Update BHL Set HoTen='" +txtHoten.Text +"',MaDB='"+cbdoibong.SelectedItem.ToString()+"',ChucVu='"+cbchucvu.SelectedItem.ToString()+"'   where MaBHL='" + txtMabhl.Text + "' ";
                db.ExecNonQuery(sql);
                MessageBox.Show("Insert Successful!", "Message", MessageBoxButtons.OK);
                string sql2 = "select * from bhl";
                dataGridViewdsdb.DataSource = db.ExecSQLDataTable(sql2);
                LoadBHL();
            }
            catch (Exception)
            { }
        }

        

    }
}
